﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AfvandingService
{
    public class Pumpe
    {
        #region Fields
        private double _pumpekapacitet; // Pumpekapacitet pr. time i m3
        private int _pumpenr;
        private bool _status = false; // True = kører, false = stoppet
        private int _pumpestationsNr;
        #endregion

        #region ctor

        // skal bruges til serialization
        public Pumpe()
        {

        }

        public Pumpe(double pumpekapacitet, int pumpenr, int pumpestationsnr)
        {
            _pumpekapacitet = pumpekapacitet;
            _pumpenr = pumpenr;
            _pumpestationsNr = pumpestationsnr;
        } 
        #endregion

        #region Methods

        public void Start(Pumpestation pump)
        {
            if (_status == false)
            {
                _status = true;
                while (_status == true)
                {

                    if (pump.Vandstand > _pumpekapacitet / 3600)
                    {
                        pump.Vandstand -= _pumpekapacitet / 3600; 
                    }
                    Thread.Sleep(1000);
                }
            }
        }

        public bool Stop()
        {
            if (_status == true)
            {
                _status = false;
                return true;
            }
            else
            {
                return true;
            }
        }


        #endregion

        #region Properties
        public double Pumpekapacitet { get { return _pumpekapacitet; } set { _pumpekapacitet = value; }}
        public int Pumpenr { get { return _pumpenr; } set { _pumpenr = value; }}
        public bool Status { get { return _status; } set { _status = value; } }
        public int PumpestationsNr { get { return _pumpestationsNr; } set { _pumpestationsNr = value;  } }
        #endregion
    }
}
